<%--
  Created by IntelliJ IDEA.
  User: WYX
  Date: 2024/3/29
  Time: 8:57
  To change this template use File | Settings | File Templates.
--%>
<%@ page import="java.util.Objects" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>day02.2.jsp</title>
</head>
<body>
<%
    String num1 = request.getParameter("num1");
    String flag =request.getParameter("flag");
    String num2 = request.getParameter("num2");
    if (num1 == null || num2 == null || num1.isEmpty() || num2.isEmpty()) {
        response.sendRedirect("day02.1.jsp");
        return;
    }
    try {
        double a = Double.parseDouble(num1);
        double b = Double.parseDouble(num2);
        double r = 0;
        if(Objects.equals(flag, "+"))r=a+b;
        else if(Objects.equals(flag, "-"))r=a-b;
        else if(Objects.equals(flag, "*"))r=a*b;
        else if(Objects.equals(flag, "/"))r=a/b;
        else if(Objects.equals(flag, "%"))r=a%b;
        out.println(a + flag + b + '=' + r);
    }catch (Exception e){
        out.print("请输入数字字符");
    }
%>
</body>
</html>
